export const ValidateRules = {
  required: (value: any) => {
    return value === 0 || !!value || '必填'
  },

  maxLength: (value: any, length: number) => {
    return value.length <= length || `最大长度${length}`
  },

  email: (value: any) => {
    const pattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return pattern.test(value) || !value || '无效邮箱'
  },
  mobile: (value: any) => {
    const pattern = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/
    return pattern.test(value) || !value || '无效手机号'
  },
  telephone: (value: any) => {
    const pattern = /^([1]\d{10}|([\(（]?0[0-9]{2,3}[）\)]?[-]?)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?)$/
    return pattern.test(value) || '无效电话'
  },
  password: (value: string) => {
    const pattern = new RegExp(/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,25}$/);
    return (pattern.test(value) && value.length > 7) || !value || '密码格式错误，请输入8-25位的密码，密码必须包含大写字母、小写字母、数字、符号四种中的三种'
  },

  passwordConfirm: (pwd:string, pwdConfirm:string) => {
    return (pwd === pwdConfirm) || '密码不一致'
  },

  dictLenth: (value: string) => {
    return (value || "").length <= 15 || "最长只能15个字符"
  },

  dictName: (value: string) => {
    const pattern = /[\s]+/;
    return !pattern.test(value) || "请输入正确的字典名称."
  },

  username: (value: string) => {
    return !!value || "请输入正确的账号."
  },

  magcode: (value: any) => {
    return  value.length > 3 || "请输入正确的验证码"
  },

  number: (value: any) => {
    return  value.length > 3 || "请输入正确的验证码."
  },

  userNo: (value: any) => {
    const pattern = new RegExp(/^[a-zA-Z0-9]{1,}$/);
    return pattern.test(value) || !value || '只能输入字母和数字'
  },

  fixTwo: (value: any) => {
    const pattern = new RegExp(/^\d+(\.\d{0,2})?$/);
    return pattern.test(value) || !value || '只能输入不超过两位小数的数字'
  },

  idNo: (value: any) => {
    const pattern = (/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/ || /^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$/);
    return pattern.test(value) || !value || '无效身份证'
  },

  idCard: (value: any) => {
    const pattern = /^([1-9]{1})(\d{15}|\d{16}|\d{17}|\d{18})$/;
    return pattern.test(value) || !value || '请输入正确的纯数字银行卡号'
  },
}
